//============================================================================
// Name        : GasPump.cpp
// Author      : Thada Pipatcharoenkij 49270325
// Description : GasPump, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

/**
 * GasPump class to simulate dispense gas(gallon unit) and calculate total charge
 * according to cost per gallon.
 */
class GasPump {

public:
	GasPump();
	void displayDispense();
	void displayCharge();
	void displayCostPerGallon();
	void stopDispense();
	void startDispense();
	void dispense(double);

private:
	/** state of GasPump */
	bool start;
	/** amount of dispensed gas */
	double dispenseValue;
	/** total charge */
	double charge;
	/** cost per gallon */
	double costPerGallon;
};

/**
 * Constructor to initial value
 */
GasPump::GasPump(){
	dispenseValue = 0;
	charge = 0;
	start = false;
	costPerGallon = 1.5;
}

/**
 * To display total charge cost.
 */
void GasPump::displayCharge(){
	cout << "Total charge " << charge << endl;
}

/**
 * To display amount of dispensed gas.
 */
void GasPump::displayDispense(){
	cout << "Amount of dispense " << dispenseValue << endl;
}

/**
 * To display cost per gallon.
 */
void GasPump::displayCostPerGallon(){
	cout << "Cost Per Gallon " << costPerGallon << endl;
}

/**
 * To start dispense process.
 */
void GasPump::startDispense(){
	start = true;
}

/**
 * To stop dispense process.
 */
void GasPump::stopDispense(){
	start = false;
}

/**
 * To dispense by amount of dispense value
 * @param amount the value of dispensed gas.
 */
void GasPump::dispense(double amount){
	if (start){ //need to start first
		cout << "Amount of dispense: " << amount << endl;
		dispenseValue += amount;
		charge += (amount * costPerGallon);
	}
	else {
		cout << "Dispense process has not started yet." << endl;
	}
}

/**
 * main method to run simulation of GasPump
 */
int main() {
	int i = 0;
	GasPump gp;
	gp.startDispense(); //start process
	while(i < 10){
		int value = rand() % 100;
		gp.dispense(value);
		i++;
	}
	gp.stopDispense(); //stop process
	gp.displayCostPerGallon();
	gp.displayDispense();
	gp.displayCharge();
	return 0;
}
